<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/3/29
 * Time: 15:14
 */
namespace app\business\controller;

use think\Db;
use think\Session;

class Apply extends Common
{
	//判断是否登录
	public function _initialize()
	{
		parent::_initialize();
	}
	
	/**
	 * 发起申请结算记录首页
	 * @param string get.date 申请时间
	*/
	public function index()
	{
		$where = ['query'=>[]];
		$db = Db::table('apply')
				->group('date')
				//->where('status',1)
				->where('bid',Session::get('business.id'));
		if(!empty(trim(input('get.date')))){
			$date = trim(input('get.date'));
			$info = explode('-',$date);
			$timestamp = getStartAndEndUnixTimestamp($info[0],$info[1],$info[2]);
			$db->where('date','>',$timestamp['start'])->where('date','<',$timestamp['end']);
			$where['query']['date'] = $date;
		}
		$result = $db->order('id desc')->paginate(8,false,$where);
		return view('index',compact('result','date'));
	}
	
	/**
	 * 详情
	 * @param string get.date 发起时间
	*/
	public function detail()
	{
		$date = input('get.date');
		$result = Db::table('postpayment')
			->field('product.pname,postpayment.ordernumber,postpayment.date,apply.status,apply.number as anumber')
			->join('product','product.id = postpayment.pid','LEFT')
			->join('apply','apply.postid = postpayment.id','RIGHT')
			->where('apply.date',$date)
			->where('apply.bid',Session::get('business.id'))
			->order('apply.id desc')
			->paginate(10);
		return view('detail',compact('result'));
	}
}